package bai5.service.implement;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import bai5.service.EmployeeAPI;

public class EmployeeDAO implements EmployeeAPI{

	public int tuoi(String date) throws ParseException {
		Calendar today=Calendar.getInstance();
		SimpleDateFormat sf=new SimpleDateFormat("dd/mm/yyyy");
		Calendar birthday=Calendar.getInstance();
		Date d=sf.parse(date);
		birthday.setTime(d);
		int age=today.get(Calendar.YEAR)-birthday.get(Calendar.YEAR);
		if(today.get(Calendar.DAY_OF_YEAR)<=birthday.get(Calendar.DAY_OF_YEAR))
		return age-1;
		return age;
	}

	public int thamNien(String date) throws ParseException {
		Calendar today=Calendar.getInstance();
		Calendar startDate=Calendar.getInstance();
		SimpleDateFormat sf=new SimpleDateFormat("dd/mm/yyyy");
		startDate.setTime(sf.parse(date));
		int kq=today.get(Calendar.YEAR)-startDate.get(Calendar.YEAR);
		if(today.get(Calendar.MONTH)<=startDate.get(Calendar.YEAR))
		return kq-1;
		return kq;
	}

	public String loaiCV(int i) {
		String cv="";
		switch(i){
		case 1:cv="Truong nhom";
		break;
		case 2:cv="Truong du an";
		break;
		case 3:cv="Nhan vien";
		break;
		}
		return cv;
	}

	public int pcThamnien(int i) {
		int phucap=0;
		if(i>5){
			phucap=1000000;
		}
		else if(2<=i && i<5){
			phucap=500000;
		}
		else {
			phucap=0;
		}
		return phucap;	
	}

	public int pcChucvu(int i) {
		int pccv=0;
		switch(i){
		case 1:  pccv=500000;break;
		case 2: pccv=1000000;break;
		default: pccv=0;
		}
		return pccv;
	}

	public boolean isValiDate(String date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		try {
			dateFormat.setLenient(false);
			dateFormat.parse(date);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public String formatNumber(int number) {
		NumberFormat formatter = new DecimalFormat("###,###");
		String resp = formatter.format(number);
		resp = resp.replaceAll(",", " ");
		return resp;
	}

}
